package com.edu.modules.baseinfo.api;

import com.alibaba.fastjson.JSONObject;
import com.edu.modules.baseinfo.model.LessonRecord;
import com.edu.modules.baseinfo.service.LessonRecordService;
import com.edu.modules.baseinfo.vo.ResultVo;
import com.sari.common.utils.RequestContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author kwj
 * @version 2016-08-01
 */
@CrossOrigin
@Controller
@RequestMapping(value = "lessonRecord")
public class LessonRecordApi {

    private static Logger log = LoggerFactory.getLogger(LessonRecordApi.class);

    @Autowired
    private LessonRecordService lessonRecordService;


    @ResponseBody
    @RequestMapping(value = "save")
    public ResultVo saveLesson(HttpServletRequest request){

        JSONObject param = RequestContextUtils.readJson(request);
        return lessonRecordService.saveLessonRecord(param);
    }

    @ResponseBody
    @RequestMapping(value="/videoUpload", method= RequestMethod.POST)
    public JSONObject doUploadVideo(@RequestParam("file") MultipartFile file){

        return lessonRecordService.doUploadVideo(file);
    }

    @ResponseBody
    @RequestMapping(value = "getLessonRecordByPage")
    public JSONObject getLessonRecordByPage(HttpServletRequest request) {

        JSONObject param = RequestContextUtils.readJson(request);
        return lessonRecordService.getLessonRecordByPage(param);
    }

    @ResponseBody
    @RequestMapping(value = "update")
    public JSONObject updateLessonRecord(HttpServletRequest request){

        JSONObject param = RequestContextUtils.readJson(request);
        lessonRecordService.updateLessonRecord(param);
        JSONObject result = new JSONObject();
        result.put("success",true);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "delete")
    public ResultVo deleteLessonRecord(String lessonRecordId) {

        return lessonRecordService.deleteLessonRecord(lessonRecordId);
    }

}
